package cn.me.alphamq.common.sync.impl;

import cn.me.alphamq.common.sync.StopWatch;

/**
 * 使用 Object 的方法制作的停表
 *
 * @author f
 */
public class ObjectStopWatch implements StopWatch {

    /**
     * 用于暂停线程运行的停表
     */
    private final Object stopWatch = new Object();

    @Override
    public void pause() {
        synchronized (stopWatch) {
            try {
                stopWatch.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

    @Override
    public void resume() {
        synchronized (stopWatch) {
            stopWatch.notify();
        }
    }
}
